import download from 'downloadjs'
export const handleDownload = async (url: any) => {
  if (url) download(url)
}

export const handleDownloadOld = async (url: any) => {
  // window.location.href = url
  try {
    const response = await fetch(url)
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`)
    }

    const blob = await response.blob()
    const urlObject = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = urlObject
    link.setAttribute('download', '') // 或者指定文件名，例如 'example.pdf'
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
    window.URL.revokeObjectURL(urlObject)
  } catch (error) {
    console.error('Error downloading file:', error)
  }
}
